package com.example.forum.controller;

import com.example.forum.common.AppResult;
import com.example.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: wenjingyuan
 * @Date: 2023/09/14/14:46
 * @Description:
 */
@Api(tags="测试类的相关接口")
//表示返回的结果是数据而不是一个URL
@RestController
//定义一级映射路径
@RequestMapping("/test")
public class TestController {
    @ApiOperation("测试接口1：显示你好springboot")
    @GetMapping("/hello")
    public String hello(){
        return "hello springboot";
    }

    @ApiOperation("测试接口2：显示一个异常信息")
    @GetMapping("/exception")
    public AppResult exception() throws Exception {
        throw new Exception("这是一个exception异常");
    }

    @ApiOperation("测试接口3：显示一个自定义异常信息")
    @GetMapping("/applicationException")
    public AppResult applicationException(){
        throw new ApplicationException("这是一个ApplicationException异常");
    }

    @ApiOperation("测试接口4:根据姓名打印hello")
    @PostMapping("/helloByName")
    public AppResult helloByName(@ApiParam("姓名") @RequestParam("name") String name){
        return AppResult.success("hello"+name);
    }
}
